package com.example.team_awesome_funf;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import edu.mit.media.funf.storage.NameValueDatabaseHelper;

public class DBAccess {
	
	//Query for selecting location probe data from GPS and not cached wifi positions
	private static final String FIRST_LOCATION_SQL = "SELECT value FROM " +
	NameValueDatabaseHelper.DATA_TABLE.name +
	" WHERE name = 'edu.mit.media.funf.probe.builtin.LocationProbe' and value not like '%cached%';";
	
	//Query for getting accelerometer probe data
	private static final String ACC_SQL = "SELECT value FROM " +
			NameValueDatabaseHelper.DATA_TABLE.name +
			" WHERE name = 'edu.mit.media.funf.probe.builtin.AccelerometerSensorProbe';";
	
	public DBAccess()
	{
	}
	
	public String[] GetLocationProbeData(SQLiteDatabase sqlLiteDb)
	{
		SQLiteDatabase db = sqlLiteDb;
	    Cursor mcursor = db.rawQuery(FIRST_LOCATION_SQL, null);
	    String[] arrayOfLocationData = new String[mcursor.getCount()];
	    mcursor.moveToFirst();
	    
	    int counter = 0;
	    while(mcursor.isAfterLast() == false)
	    {
	    	arrayOfLocationData[counter] = mcursor.getString(0);
	    	mcursor.moveToNext();
	    	counter++;
	    }
	    
	    return arrayOfLocationData;
	    
	    
	}
	
	public String GetAccData(SQLiteDatabase sqlLiteDb)
	{
		String accString = "";
		SQLiteDatabase db = sqlLiteDb;
	    Cursor mcursor = db.rawQuery(ACC_SQL, null);
	    mcursor.moveToFirst();
	    
	    while(mcursor.isAfterLast() == false)
	    {
	    	accString = accString + "\n\n" + mcursor.getString(0);
	    	mcursor.moveToNext();
	    }
	    
	    System.out.println(accString);
	    //db.close();
	    return accString;
	}

}
